package com.hongawen.lambda;


import com.hongawen.common.pojo.User;
import com.hongawen.lambda.demo.LambdaSingleReturnSingleParmeter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年04月26日 10:38
 */
public class LambdaObj {


    void getAllInfo(User user, Consumer<User> consumer) {
        consumer.accept(user);
    }


    public static void main(String[] args) {
        List<User> userList = Arrays.asList(new User("hongawen", 23, "男"), new User("hongawen", 45, "男"));
        List<User> userList1 = new ArrayList<>(userList);
        User user = new User("hongawen", 56, "男");
        LambdaObj lambdaObj = new LambdaObj();
        lambdaObj.getAllInfo(user, userTemp -> System.out.println(userTemp.getName() + userTemp.getAge()));
        lambdaObj.getAllInfo(user, System.out::println);
        userList.forEach(System.out::println);
        userList1.removeIf(a -> a.getAge() == 32);
        userList1.forEach(a -> System.out.println(a.getName()));
        //简化
        LambdaSingleReturnSingleParmeter lambda4 = a -> {
            a=change(a);
            System.out.println(a);
            return a;
        };
        System.out.println(lambda4.test(5));
        //方法引用
        LambdaSingleReturnSingleParmeter lambda5 = LambdaObj::change;
        System.out.println(lambda5.test(7));
        Consumer<User> consumer = System.out::println;
        consumer.accept(user);
    }

    /**
     * 自定义的实现方法
     */
    private static int change(int a) {
        return a * 2;
    }

}
